package com.baidu.baiduyun;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

@SuppressWarnings("serial")
public class FileUrlServlet extends HttpServlet {

	private static final Log log = LogFactory.getLog(FileUrlServlet.class);

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String fileName = new String(request.getParameter("fileName").getBytes(
				"ISO8859-1"), "utf-8");
		String generateUrl = Baidu.generateUrl(fileName);
		if (log.isDebugEnabled()) {
			log.debug("request filename:"+fileName);
		}
		response.setHeader("fileUrl", generateUrl);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}
}
